{% extends "base.html" %}
{# Copyright The IETF Trust 2015, All Rights Reserved #}
{% load origin %}
{% load static %}
{% load django_bootstrap5 %}
{% load ietf_filters %}
{% block title %}
    {% if group %}
        Edit {{ group.type.name }} {{ group.acronym }}
    {% else %}
        Start chartering new group
    {% endif %}
{% endblock %}
{% block pagehead %}{{ form.media.css }}{% endblock %}
{% block content %}
    {% origin %}
    <h1>
        {% if action == "edit" %}
            Edit {{ group.type.name }}
            <br>
            <small class="text-body-secondary">{{ group.acronym }}</small>
        {% elif action == "charter" %}
            Start chartering new group
        {% else %}
            Create new group or BOF
        {% endif %}
    </h1>
    {% if not request.user.is_authenticated %}
        <p class="alert alert-info my-3">
            Note that persons with authorization to manage information, e.g.,
            chairs and delegates, need a datatracker account to actually do
            so. New accounts can be
            <a href="{% url "ietf.ietfauth.views.create_account" %}">created here</a>.
        </p>
    {% endif %}
    <form class="my-3 form-horizontal" method="post">
        {% csrf_token %}
        {% bootstrap_form form layout='horizontal' %}
        {% if action == "edit" %}
            <button class="btn btn-primary" type="submit">Submit</button>
            <a class="btn btn-secondary float-end" href="{{ group.about_url }}">Back</a>
        {% elif action == "charter" %}
            <button class="btn btn-primary" type="submit">Start chartering</button>
        {% else %}
            <button class="btn btn-primary" type="submit">Create group or BOF</button>
        {% endif %}
    </form>
{% endblock %}
{% block js %}
    {{ form.media.js }}
    <script>
        $(document).ready(function () {
            $("#id_acronym").closest(".mb-3").each(function() {
                // fixup styling a bit in case the confirm checkbox is shown
                if ($(this).next().find("#id_confirm_acronym").length > 0) {
                    $(this).css("margin-bottom", 0);
                    $(this).find(".form-text").css("margin-bottom", 0);
                    if ($(this).hasClass("is-invalid"))
                    $(this).next().addClass("is-invalid");
                }
            });
        });
    </script>
{% endblock %}